#ifndef IMAGEDETECT_H
#define IMAGEDETECT_H

#include <vector>
#include <opencv/cv.h>
//#include <opencv2/core/core.hpp>
//#include <opencv2/highgui/highgui.hpp>
//#include <opencv2/features2d/features2d.hpp>
//#include <opencv2/imgproc/imgproc.hpp>
//#include <opencv2/cvconfig.h>
//#include <opencv2/highgui.hpp>

#include <mutex>



class WhitePoint
{
public:
    //点的坐标
    float x;
    float y;
    float dis; //最后排序时候,到基端点的距离
};


class ImageDetect
{
public:
    static ImageDetect& GetInstance();//获取实例
    ImageDetect& operator = (const ImageDetect&) = delete;
    ImageDetect(const ImageDetect&) = delete;
//    ~ImageDetect();
private:
    static ImageDetect m_Instance;
    ImageDetect();


public:
    void DetectThread();
    std::vector <cv::Point2f> GetObjectPoints();

public:
    std::mutex m_dstImageMtx;
    cv::Mat m_dstImage;

private:
//    Mat m_outImg;     //二值化图片
    void Detect();
    void FrameProcess(cv::Mat &img);
    void ContoursProcess(std::vector<std::vector<cv::Point>> &contours);
    void FindGravity(const std::vector<std::vector<cv::Point>> &contours);
    void ShowImage(const cv::Mat &image);


//    int FindWhitePoint(std::vector<std::vector<cv::Point> > &contours);
//    void process_together(std::vector<cv::Point>& contour,int th,std::vector<std::vector<cv::Point> >& div_contours);
//    int div_point_once(std::vector<cv::Point>& contour,int th,std::vector<std::vector<cv::Point> >& div_contours,std::vector<std::vector<cv::Point> >& together_contours);
//    void noise_remove(std::vector<std::vector<cv::Point> > &contours);
//    int Preprocese(std::vector<std::vector<cv::Point> > &contours);

private:
    const unsigned int OBJECT_SIZE_MAX = 20;
    const int WIDTH = 720;
    const int HEIGHT = 576;
    std::mutex m_objectPointsMtx;// 同步锁
    std::vector <cv::Point2f> m_objectPoints;



//    cv::Mat m_originalImg;     //输入灰度图像的拷贝
//    std::vector<WhitePoint> m_pointInFrame;       //Frame中白点
//    cv::Mat m_contoursImg;// = Mat::zeros(pro_img.rows,pro_img.cols,CV_8UC1); //纯黑的图
//    cv::Mat m_temp_img;
//    int m_OSTU;

    //    vector<WhitePoint> mPointInFrameOut;    //最终输出的带编号的白点
    //    int mPointNum;  //点的数量
    //    vector<CvPoint2D32f> m_pointInFrame;


};
//extern ImageDetect imgdetect;
#endif // IMAGEDETECT_H
